package com.f1ashback.bus.controller;

import com.f1ashback.bus.Qo.StationQo;
import com.f1ashback.bus.Vo.StationGet;
import com.f1ashback.bus.Vo.StationVo;
import com.f1ashback.bus.common.AjaxResult;
import com.f1ashback.bus.entity.Station;
import com.f1ashback.bus.service.StationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sta")
@CrossOrigin(origins = "*", maxAge = 3600)
public class StationController {

    @Autowired
    private StationService stationService;

    @GetMapping("/list")
    public AjaxResult list() {
        Map<String,List<StationVo>> res = new HashMap<>();
        List<StationVo> list = stationService.listBus();
        res.put("res",list);
        if (list.isEmpty()) {
            return AjaxResult.error("未获取到数据！");
        }
        return AjaxResult.success(res);
    }

    @GetMapping("/listSta")
    public List<StationVo> appListSta() {
        return stationService.appListSta();
    }

    @GetMapping("/getStaInfo")
    public List<StationVo> getStaInfoByStaName(String staName){
        return stationService.getStaInfoByStaName(staName);
    }

    @GetMapping("/staName")
    public AjaxResult getStaName(){
        return stationService.getStaName();
    }

    @DeleteMapping("/del/{staId}")
    public AjaxResult deleteSta(@PathVariable Long staId){
        return stationService.deleteSta(staId);
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody StationGet station){
        return stationService.add(station);
    }

    @PutMapping("/update")
    public AjaxResult update(@RequestBody StationGet stationGet){
        return stationService.updateStation(stationGet);
    }

    @PostMapping("/querySta")
    public AjaxResult querySta(@RequestBody StationQo stationQo){
        return stationService.querySta(stationQo);
    }

    @GetMapping("/getStaLevel")
    public AjaxResult getStaLevel(){
        return stationService.getStaLevel();
    }
}
